package net.oschina.app.fragment.favorite;

import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import net.oschina.app.R;
import net.oschina.app.adapter.my.FansAdapter;
import net.oschina.app.bean.Friend;
import net.oschina.app.bean.FriendsList;
import net.oschina.app.constant.Constants;
import net.oschina.app.fragment.BaseFragment;
import net.oschina.app.util.UIUtils;
import net.oschina.app.util.URLGet;

import java.util.List;

/**
 * Created by YL on 2017/4/2.
 */
public abstract class BaseMsgFragment extends BaseFragment {
    private XRecyclerView mView;
    private List<Friend> mFriends;


    @Override
    protected View initView() {
        mView = (XRecyclerView) View.inflate(UIUtils.getContext(), R.layout.f_software_fragment, null);
        mView.setLayoutManager(new LinearLayoutManager(getActivity()));
        return mView;
    }

    @Override
    protected void setData() {
        String path = Constants.Friends_Path + getPosition() + Constants.End_Path; //http://localhost:8080/oschina/list/friends_list1/page0.xml
        URLGet urlGet = new URLGet();
        urlGet.getData(path, FriendsList.class, new URLGet.OnURLGetLitener<FriendsList>() {
            @Override
            public void showSuccess(FriendsList bean) {
                mFriends = bean.getFriendlist();
                dealCommonSuccess(mFriends);
            }

            @Override
            public void showError(Exception e) {

            }
        });
    }

    protected abstract String getPosition();

    @Override
    protected void showSuccess() {
        FansAdapter adapter = new FansAdapter(mFriends);
        mView.setAdapter(adapter);
        changeView(mView);
    }
}
